package com.tdf.lolpanel.context;

import java.util.HashMap;
import java.util.Map;

/**
 * ThreadLocal
 */
public class BaseContext {

    public static final ThreadLocal<Map<String, String>> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 获取线程map
     * @return
     */
    public static Map<String, String> getLocalMap() {
        Map<String, String> map = THREAD_LOCAL.get();
        if (map == null) {
            map = new HashMap<>(10);
            THREAD_LOCAL.set(map);
        }
        return map;
    }

    /**
     * 添加信息到map中
     * @param key
     * @param value
     */
    public static void set(String key, String value) {
        Map<String, String> map = getLocalMap();
        map.put(key, value);
    }

    /**
     * 获得线程map中的数据
     */
    public static String get(String key) {
        Map<String, String> map = getLocalMap();
        return map.get(key);
    }
}
